package generator;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.gee.cloud.common.core.domain.entity.BaseEntity;
import com.github.yulichang.base.MPJBaseMapper;

import java.util.Collections;

/**
 * @author gepengjun
 * @since 2022/8/11 10:31
 */
public class NewMybatisPlusGeneration {

    public static void main(String[] args) {
        String projectPath = System.getProperty("user.dir");
        FastAutoGenerator.create(
                        "jdbc:mariadb://172.23.9.121:3307/aerospace_simulate?useUnicode=true&characterEncoding=utf-8&useSSL=false",
                        //"jdbc:mariadb://mariadb.gee.cn:3306/center_config?useUnicode=true&characterEncoding=utf-8&useSSL=false",
                        "root", "123456")
                .globalConfig(builder -> {
                    builder.author("gee") // 设置作者
                            .enableSwagger()
                            .outputDir(projectPath + "/src/main/java") // 指定输出目录
                            .disableOpenDir()
                    ;
                })
                .packageConfig(builder -> {
                    builder.parent("com.gee.spring.cloud.aerospace.simulate") // 设置父包名
                            .moduleName("mgt") // 设置父包模块名

                            .pathInfo(Collections.singletonMap(OutputFile.xml, null)) // 设置mapperXml生成路径
                    ;
                })
                .strategyConfig(builder -> {
                    builder.addInclude("gee_cloud_satellite_telemetry_dsl") // 设置需要生成的表名
                            .addTablePrefix("gee_cloud_")
                            .entityBuilder()
                            .idType(IdType.AUTO)
                            .enableLombok()
                            .enableTableFieldAnnotation()
                            .superClass(BaseEntity.class)
                            .enableActiveRecord()
                            .addSuperEntityColumns("last_operate_host","last_operate_by","last_operate_time")
                            .controllerBuilder()
                            .enableRestStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .mapperBuilder()
                            .superClass(MPJBaseMapper.class)
                    ;
                })
                .execute()
                ;

    }
}
